property_exists
Überprüfen Sie, ob ein Objekt oder eine Klasse diese Eigenschaft hat
Funktionsname: Property_Exists ()
Funktion Beschreibung: Eigenschaft_Exists () überprüft, ob ein Objekt oder eine Klasse über das angegebene Attribut verfügt.
Parameter:
Rückgabewert:
Anwendbare Version: Php 4, Php 5, Php 7
Verwendungsbeispiel:
class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'name')) { echo "The 'name' property exists."; } else { echo "The 'name' property does not exist."; } // 输出:The 'name' property exists.
class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'age')) { echo "The 'age' property exists."; } else { echo "The 'age' property does not exist."; } // 输出:The 'age' property does not exist.
class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'name')) { echo "The 'name' static property exists."; } else { echo "The 'name' static property does not exist."; } // 输出:The 'name' static property exists.
class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'age')) { echo "The 'age' static property exists."; } else { echo "The 'age' static property does not exist."; } // 输出:The 'age' static property does not exist.